package com.cloudbroker.bcs.platform.dav.middle.bizservice.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cloudbroker.bcs.common.util.DateTimeUtil;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.customer.vo.BrokerLoggerForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.operate.OperateBrokerBizService;
import com.cloudbroker.bcs.platform.dav.bizapi.service.operate.result.BrokerLoggerListData;
import com.cloudbroker.bcs.platform.dav.bizapi.service.operate.result.BrokerLoggerListResult;
import com.cloudbroker.bcs.platform.dav.middle.entity.BrokerAction;
import com.cloudbroker.bcs.platform.dav.middle.service.BrokerActionService;

/**
 * Created by wangxu13798 on 2016/8/17.
 */
@Service
public class OperateBrokerBizServiceImpl implements OperateBrokerBizService {
    
    @Resource
    private BrokerActionService brokerActionService;
    
    @Override
    public BrokerLoggerListResult funcBrokerLoggerQry(BrokerLoggerForm form) {
        BrokerLoggerListResult result = new BrokerLoggerListResult();
        String mobile = form.getMobile();
        String broker_id = form.getBroker_id();
        String user_id = form.getUser_id();
        Integer page_size = Integer.parseInt(form.getPage_count());
        Integer page_no = (Integer.parseInt(form.getPage_no()) - 1) * page_size;
        String tenant_id = form.getTenant_id();
        List<BrokerAction> list = brokerActionService.getBrokerLoggerList(mobile, broker_id, user_id, page_no,
                page_size, tenant_id);
        List<BrokerLoggerListData> res = new ArrayList<BrokerLoggerListData>();
        for(BrokerAction action : list){
            BrokerLoggerListData data = new BrokerLoggerListData();
            data.setAction_ip(action.getAction_ip());
            data.setAction_remark(action.getAction_remark());
            data.setAction_result(action.getAction_result());
            data.setAction_type(action.getAction_type());
            data.setBroker_id(action.getBroker_id());
            data.setBrokeraction_id(action.getBrokeraction_id());
            data.setCreate_time(DateTimeUtil.toString(action.getCreate_time(), DateTimeUtil.FORMAT_YYYYMMDDHHMMSS));
            data.setMobile(action.getMobile());
            data.setPosition_str(action.getPosition_str());
            data.setTenant_id(action.getTenant_id());
            data.setUser_id(action.getUser_id());
            res.add(data);
        }
        result.newDataList().addAll(res);
        return VOUtil.setSuccessResult(result);
    }
}
